package com.swg.wxorder.handler;

import com.swg.wxorder.config.ProjectUrlConfig;
import com.swg.wxorder.exception.SellException;
import com.swg.wxorder.exception.SellerAuthorizeException;
import com.swg.wxorder.utils.ResultVOUtil;
import com.swg.wxorder.vo.ResultVo;
import org.springframework.http.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Author 【swg】.
 * @Date 2017/12/11 21:34
 * @DESC
 * @CONTACT 317758022@qq.com
 */
@ControllerAdvice
public class SellExceptionHandler {
    @Autowired
    private ProjectUrlConfig projectUrlConfig;

    @ExceptionHandler(value = SellerAuthorizeException.class)
    public ModelAndView handlerAuthorizeException() {
        return new ModelAndView("redirect:"
                .concat("/login"));
    }

    /**针对SellException做一个统一异常处理，返回固定的格式ResultVO*/
    @ExceptionHandler(value = SellException.class)
    @ResponseBody
    public ResultVo handlerSellerException(SellException e){
        return ResultVOUtil.error(e.getCode(),e.getMessage());
    }
}
